import 'package:flutter/material.dart';
import '../model/post.dart';
import './ListViewDetailDemo.dart';

class ListViewDemo extends StatelessWidget {
  Widget _listItemBuilder(BuildContext context, int index) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.all(10.0),
      margin: EdgeInsets.only(bottom: 1.0),
      child: Stack(
        children: <Widget>[
          Column(
            children: <Widget>[
              Image.network(posts[index].imageUrl, width: 300, height: 60),
              SizedBox(height: 10),
              Text(
                posts[index].title,
                style: Theme.of(context).textTheme.title,
              ),
              SizedBox(height: 10.0),
              Text(
                posts[index].author,
                style: Theme.of(context).textTheme.subhead,
              ),
            ],
          ),
          Positioned.fill(
            child: Material(
              color: Colors.transparent,
              child: InkWell(
                splashColor: Colors.white.withOpacity(0.4),
                highlightColor: Colors.white.withOpacity(0.1),
                onTap: () {
                  Navigator.of(context).push(
                    MaterialPageRoute(builder: (context) => ListViewDetailDemo(post: posts[index],))
                  );
                },
              ),
            ),
          ),
        ],
      )
    );
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: posts.length,
      itemBuilder: _listItemBuilder,
    );
  }
}
